/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$(".btn-ed").click(function () {
    cleandata();
    var id = $(this).data("id");
    $("#prjectdesid").val(id);
    var datastr = "cont=1&projectdesid=" + id;
    $.ajax({
        url: "/../../controller/project/projectdescontroller.php",
        type: "POST",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                $("#projectdes_seq").val(result.data.seq);
                $("#projectdes_cname").val(result.data.cname);
                $("#projectdes_pname").val(result.data.pname);
                $("#projectdes_number").val(result.data.number);
                $("#projectdes_code").val(result.data.code);
                $("#projectdes_info").val(result.data.info);
                $("#projectdes_intro").val(result.data.intro);
                $("#projectdes_introhtml").val(result.data.introhtml);
                $("#projectdes_type").val(result.data.type);
            } else {
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
});

$(".btn-add").click(function () {
    cleandata();
    $("#prjectdesid").val(0);
    var datastr = "cont=2";
    $.ajax({
        url: "/../../controller/project/projectdescontroller.php",
        type: "POST",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                $("#projectdes_number").val(result.data);
                return;
            }
        }
    });
});

$("#submitchangedes").click(function () {
    var projectdesid = $("#prjectdesid").val();
    var seq = $("#projectdes_seq").val();
    var cname = $("#projectdes_cname").val();
    var pname = $("#projectdes_pname").val();
    var number = $("#projectdes_number").val();
    var code = $("#projectdes_code").val();
    var info = $("#projectdes_info").val();
    var intro = $("#projectdes_intro").val();
    var introhtml = $("#projectdes_introhtml").val();
    var type = $("#projectdes_type").val();
    var datastr = "";
    if (projectdesid == 0) {
        if (seq == "" || cname == "" || number == "" || code == "") {
            layer.msg('信息请填写完整', {
                time: 2000, //20s后自动关闭
                btn: ['OK']
            });
            return;
        } else {
            datastr += "cont=3";
            datastr += "&cname=" + cname;
            datastr += "&pname=" + pname;
            datastr += "&number=" + number;
            datastr += "&code=" + code;
            datastr += "&info=" + info;
            datastr += "&intro=" + intro;
            datastr += "&introhtml=" + introhtml;
            datastr += "&type=" + type;
            datastr += "&seq=" + seq;
        }
    } else {
        if (seq == "" || cname == "" || number == "" || code == "") {
            layer.msg('信息请填写完整', {
                time: 2000, //20s后自动关闭
                btn: ['OK']
            });
            return;
        } else {
            datastr += "cont=4";
            datastr += "&cname=" + cname;
            datastr += "&pname=" + pname;
            datastr += "&number=" + number;
            datastr += "&code=" + code;
            datastr += "&info=" + info;
            datastr += "&intro=" + intro;
            datastr += "&introhtml=" + introhtml;
            datastr += "&type=" + type;
            datastr += "&seq=" + seq;
            datastr += "&projectdesid=" + projectdesid;
        }
    }
    $.ajax({
        url: "/../../controller/project/projectdescontroller.php",
        type: "POST",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                }, function () {
                    window.location.reload();
                });
            } else {
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
});

$(".btn-dt").click(function(){
    var id = $(this).data("id");
    var datastr = "cont=5&projectdesid=" + id;
    $.ajax({
        url: "/../../controller/project/projectdescontroller.php",
        type: "POST",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                }, function () {
                    $("#userlist" + id).css("display","none");
                });
            } else {
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
});

function deleteall(ids){
    var datastr = "cont=6&ids=" + ids;
    $.ajax({
        url: "/../../controller/project/projectdescontroller.php",
        type: "POST",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                }, function () {
                    window.location.reload();
                });
            } else {
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
}

function cleandata() {
    $("#prjectdesid").val("");
    $("#projectdes_seq").val("");
    $("#projectdes_cname").val("");
    $("#projectdes_pname").val("");
    $("#projectdes_number").val("");
    $("#projectdes_code").val("");
    $("#projectdes_info").val("");
    $("#projectdes_intro").val("");
    $("#projectdes_introhtml").val("");
}